package demoMod.stsconsole.powers;

import demoMod.stsconsole.core.AbstractCreature;
import demoMod.stsconsole.helpers.DamageInfo;
import demoMod.stsconsole.interfaces.DamageSubscriber;

public class StrengthPower extends AbstractPower implements DamageSubscriber {
    public static final String ID = "StrengthPower";

    public StrengthPower(AbstractCreature owner, int amount) {
        super(ID, owner, amount);
        if (amount > 0) {
            this.type = PowerType.BUFF;
        } else {
            this.type = PowerType.DEBUFF;
        }
    }

    @Override
    public String getUpdatedDescriptions() {
        if (this.amount[0] >= 0) {
            return String.format(this.description, this.amount[0]);
        } else {
            return String.format(this.powerStrings.get(2), -this.amount[0]);
        }
    }

    @Override
    public void stackAmount(int[] amount) {
        super.stackAmount(amount);
        if (this.amount[0] <= 0) {
            this.type = PowerType.DEBUFF;
            if (this.amount[0] == 0) {
                this.onRemove();
            }
        } else {
            this.type = PowerType.BUFF;
        }
    }

    @Override
    public float onAttackToChangeDamage(float damageAmount, DamageInfo info, AbstractCreature target) {
        if (info.type == DamageInfo.DamageType.NORMAL && info.source == this.owner) {
            return damageAmount + this.amount[0];
        }
        return damageAmount;
    }
}
